package com.baichang.taoshunda.service.impl;

import com.baichang.framework.model.Page;
import com.baichang.taoshunda.dao.CommonProblemDao;
import com.baichang.taoshunda.entity.CommonProblem;
import com.baichang.taoshunda.service.CommonProblemService;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/3/1 0001.
 */
@Service
public class CommonProblemServiceImpl implements CommonProblemService {

    @Autowired
    private CommonProblemDao commonProblemDao;

    /**
     * @return
     */
    @Override
    public List<Map<String, Object>> queryAnswer(Integer type) {

        return commonProblemDao.queryAnswer(type);
    }

    /**
     * @param question
     * @param answer
     * @param type
     * @return
     */
    @Override
    public long addProblem(String question, String answer, Integer type) {
        CommonProblem commonProblem = new CommonProblem();
        commonProblem.setQuestion(question);
        commonProblem.setAnswer(answer);
        commonProblem.setType(type);
        return commonProblemDao.save(commonProblem);
    }

    /**
     * @param id
     * @param question
     * @param answer
     * @param type
     * @return
     */
    @Override
    public int updateProblem(Integer id, String question, String answer, Integer type) {
        Map map = new HashedMap();
        map.put("question", question);
        map.put("answer", answer);
        map.put("type", type);
        return commonProblemDao.update(map, id);
    }

    /**
     * @param id
     * @return
     */
    @Override
    public int deleteProblem(Integer id) {
        return commonProblemDao.deleteById(id);
    }

    /**
     * @param nowPage
     * @param pageSize
     * @return
     */
    @Override
    public Page queryProblem(int nowPage, int pageSize) {
        return commonProblemDao.queryProblem(nowPage, pageSize);
    }
}
